#include "orangepch.h"
#include "SubTexture2D.h"

namespace Orange {
	SubTexture2D::SubTexture2D(const Ref<Texture>& texture, const glm::vec2& min, const glm::vec2& max) :m_Texture(texture)
	{

		m_TexCoord[0] = { min.x,max.y};
		m_TexCoord[1] = { max.x,max.y };
		m_TexCoord[2] = { max.x,min.y };
		m_TexCoord[3] = { min.x,min.y };

	}
	
	SubTexture2D::~SubTexture2D()
	{
	}
	Ref<SubTexture2D> SubTexture2D::Create(const Ref<Texture>& texture, const glm::vec2& coord, const glm::vec2& spriteSize)
	{
		glm::vec2 min = { (coord.x* spriteSize.x) / texture->GetWidth() , (coord.y * spriteSize.y) / texture->GetHeight() };
		glm::vec2 max = { ((coord.x + 1)* spriteSize.x) / texture->GetWidth() , ((coord.y + 1) * spriteSize.y) / texture->GetHeight() };
	
		return CreateRef<SubTexture2D>(texture , min , max);
	}
}